package cn.com.acca.ma.dao.impl;

import cn.com.acca.ma.dao.UserColumnCommentDao;
import cn.com.acca.ma.dao.UserIndexesDao;
import cn.com.acca.ma.hibernate.util.HibernateUtil;
import cn.com.acca.ma.model.db.UserColumnComment;
import cn.com.acca.ma.model.db.UserIndexes;
import org.hibernate.Query;

import java.util.ArrayList;
import java.util.List;

public class UserIndexesDaoImpl extends BaseDaoImpl<UserIndexesDaoImpl> implements UserIndexesDao {

    public UserIndexesDaoImpl() {
        super();
    }

    /**
     * 查询所有记录
     * @return
     */
    @Override
    public List<UserIndexes> findAll() {
        logger.info("查询所有记录");

        List<UserIndexes> list = new ArrayList<UserIndexes>();
        session = HibernateUtil.currentSession();
        session.beginTransaction();
        Query query = session.createQuery("SELECT t FROM UserIndexes t");
        list = query.list();
        session.getTransaction().commit();
        session.close();
        return list;
    }

    /**
     * 删除索引
     * @param indexName
     */
    @Override
    public void delete(String indexName) {
        logger.info("删除索引");

        session = HibernateUtil.currentSession();
        session.beginTransaction();
        Query query = session.createSQLQuery("DROP INDEX ?");
        query.setString(0, indexName);
        query.executeUpdate();
        session.getTransaction().commit();
        session.close();
    }
}
